package cn.school.web;

import cn.school.service.SubjectService;
import cn.school.util.StringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author oldliu
 * @since 1.0
 */
@WebServlet("/delSubject")
public class SubjectDelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        Object User=req.getSession().getAttribute("USER");
//        if(User==null){
//            resp.sendError(500,"美哟权限");
//            return;
//        }

        long id= StringUtil.toLong(req.getParameter("id"));
        boolean r=SubjectService.INST.del(id);
//        if(!r){
//            resp.setContentType("text/html;charset=utf-8");
//            resp.getWriter().println("<script>alert('删除失败！');history.back();</script>");
//            return;
//        }
        req.getSession().setAttribute("msg",r?"删除成功":"删除失败@");
        resp.sendRedirect("subjectServlet");
    }
}
